#include "pch.h"
#include <iostream>
#include <future>
#include <windows.h>
using namespace std;

int PrintSome()
{
	cout << "print some thread" << GetCurrentThreadId() << endl;
	int i;
	for (i = 0; i < 10; i++)
	{
		::Sleep(1000);
		cout << i << endl;
	}
	return i;
}

std::promise<int> mpro;
std::future<int> fu;
void printfu()
{
	while (1)
	{
		if (fu._Is_ready())
			cout << "ready"<<endl;
		else
			cout << "no"<<endl;

		::Sleep(2000);
	}
}
int future()
{
	cout<<"thread:"<<GetCurrentThreadId()<<endl;
	std::future<int> m = std::async(launch::async, PrintSome);
	cout << "this m =" << m.get() << endl;

	//std::thread th(printfu);
	//th.detach();
	fu = mpro.get_future();
	if (fu._Is_ready())
		cout << "ready" << endl;
	else
		cout << "no" << endl;
	mpro.set_value(20);
	if (fu._Is_ready())
		cout << "ready" << endl;
	else
		cout << "no" << endl;

	int vv;
	cin >> vv;

	while (1)::Sleep(2000);

	return 0;
}